import javax.management.MBeanAttributeInfo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86138
 * Date: 2024-04-24
 * Time: 20:03
 */
public class test4_24 {
    public static void main1(String[] args) {
        int a = 1;
        a += 1;
        System.out.println((a));
    }

    public static void main2(String[] args) {
        int c = 10;
        long d = 20;
//        c = c + d;//err
        c += d;//用+=可以//帮你转换
        System.out.println((c));
    }

    public static void main3(String[] args) {
        System.out.println(5/2);
        //System.out.println(5/0);//err分母不能为0
    }

    public static void main4(String[] args) {
        System.out.println(10%3);
        System.out.println(-10%3);//符号看前面一个操作数
        System.out.println(11.5%2.0);//可以取模但是没什么意义
        System.out.println(1+2.0);//类型提升
    }

    public static void main5(String[] args) {
        //把字符串转换为整数
        String s = "123";
       // int a = Integer.valueOf(s);//Integer.valueOf
        int a = Integer.parseInt(s);
        System.out.println(a+1);
    }

    public static void main6(String[] args) {
        //整数变字符串
        int a = 123;
        String str = a+"";//加“”
        String str1 = String.valueOf(str);//String.valueOf
        System.out.println(str);
    }

    public static void main7(String[] args) {
        int a = 10;
        int c = 20;
        //+是连接
        System.out.println("a == "+ a );//a == 10
        System.out.println("a == " + a + c);//a == 1020
        System.out.println(a + c + " = a + c");//30 = a+c
        System.out.printf("%d",a + c);//30
    }

    public static void main8(String[] args) {
        String str1 = "hello ";
        String str2 = "world";
        System.out.println(str1+str2);
        System.out.println(str1.charAt(0));//h
    }

    public static void main9(String[] args) {
        byte a = 10;
        byte b = 10;
        int c = a + b;//不用byte因为提升成了四字节

    }

    public static void main10(String[] args) {
        int a = 10;
        long b = 20;
        long c = a + b;//发生了整型提升不能用int来定义
    }

    public static void main11(String[] args) {
        int a = 10;
        long b = 100L;//一般用大写L来区分int和long的整型

    }

    public static void main(String[] args) {
        byte a = 10;
        int b = 129;
        a = (byte)b;//-127  整型提升有误差
        System.out.println(a);
    }

    public static void main13(String[] args) {
        boolean b = true;
        System.out.println(b);
    }

    public static void main14(String[] args) {
        char ch1 = 'a';
        char ch2 = '名';
        System.out.println(ch1);
        System.out.println(ch2);//unicode字符集 char 2字节
    }

    public static void main15(String[] args) {
        double a = 1.1;
        System.out.println(a * a);//1.2100000000000002   不精确
    }

    public static void main16(String[] args) {
        float a = 1.5f;//float默认为是double类型
        System.out.println(a);
    }

    public static void main17(String[] args) {
        System.out.println(Byte.MAX_VALUE);//127
    }

    public static void main18(String[] args) {
        final int a = 10;
        //a = 20;常量无法改变
        System.out.println(a);
    }

    public static void main19(String[] args) {
        // 方式一：在定义时给出初始值
        int a = 10;
        System.out.println(a);
        // 方式二：在定义时没有给初始值，但使用前必须设置初值
        int b;
        b = 10;
        System.out.println(b);
    }
}
